{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-04-24T07:08:46.675026Z",
     "start_time": "2025-04-24T07:08:46.659963Z"
    }
   },
   "source": [
    "def calculate_average_complex(numbers):\n",
    "    total = 0\n",
    "    count = 0\n",
    "    for number in numbers:\n",
    "        total += number\n",
    "        count += 1\n",
    "    if count == 0:\n",
    "        return 0\n",
    "    else:\n",
    "        return total / count\n",
    "\n",
    "def calculate_average_simple(numbers):\n",
    "    return sum(numbers) / len(numbers) if numbers else 0\n",
    "\n",
    "# 测试两个函数\n",
    "test_data = [1, 2, 3, 4, 5]\n",
    "result_complex = calculate_average_complex(test_data)\n",
    "result_simple = calculate_average_simple(test_data)\n",
    "\n",
    "result_complex, result_simple"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3.0, 3.0)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "89f776828d139cbb"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
